package ca.cbc.msb.console.transaction;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import ca.cbc.medialib.dao.ProcessingStatusDAO;
import ca.cbc.medialib.entity.ProcessingStatus;
import ca.cbc.medialib.entity.enums.ProcessStatus;

@Named
public class ProcessingStatusTransaction {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	@Inject
	private ProcessingStatusDAO processingStatusDAO;
	
	@Transactional
    public boolean remove(long releaseId) {
		if(processingStatusDAO.findById(releaseId) == null) {
			return false;
		}
		
    	logger.info("^-^-^-^Removing process flag for release({})...", releaseId);
    	processingStatusDAO.deleteById(releaseId);
    	return true;
    }
    
	@Transactional
    public void mark(long releaseId) {
    	logger.info("^-^-^-^Marking Processing flag for release({})...", releaseId);
    	processingStatusDAO.save(new ProcessingStatus(releaseId, ProcessStatus.PROCESSING));
	}
	
	@Transactional
	public List<ProcessingStatus> list() {
		return processingStatusDAO.list();
	}
}
